package com.zerdoor.controller;

import com.zerdoor.model.UserInfo;
import com.zerdoor.pagehelper.PageHelper;
import com.zerdoor.pagehelper.PageInfo;
import com.zerdoor.service.FundManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * 资金管理
 * Created by zhongjieyu on 2015/1/29.
 */
@Controller
@RequestMapping("/fundManage")
public class FundManageController {


    @Autowired
    private FundManageService fundManageService;

    /**
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String index(HttpServletRequest request){



        return "/fundManage/view";
    }
    /**
     * 跳转资金管理页
     * @param request
     * @return
     */
    @RequestMapping(value = "withdrawIndex", method = RequestMethod.GET)
    public String withdraw(HttpServletRequest request){



        return "/fundManage/withdraw";
    }

    /**
     * 查询提现信息
     * @param request
     * @return
     */
    @RequestMapping(value = "/withdraw", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> withdraw(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);
        result.put("withdraw_id",request.getParameter("withdraw_id"));
        result.put("userName",request.getParameter("userName"));
        result.put("withdraw_status",request.getParameter("withdraw_status"));
        List<Map> list = null;
        try {

            list = fundManageService.findUserWithdraw(result);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 改变提现申请状态
     * @param withdrawStatus 状态
     * @return
     */
    @RequestMapping(value = "/changeWithdrawStatus", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> changeWithdrawStatus(HttpServletRequest request,int withdrawId,int withdrawStatus){

        Map<String, Object> result = new HashMap<String, Object>();
        try {
            //curManager

            UserInfo userInfo = (UserInfo)request.getSession().getAttribute("curManager");

            result.put("withdrawId",withdrawId);
            result.put("withdrawStatus",withdrawStatus);
            result.put("userId",userInfo.getUserId());

            fundManageService.updateWithdrawStatus(result);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        return result;
    }




}
